package com.zy.fcs.controller;

import com.alibaba.fastjson.JSONArray;
import com.zy.fcs.bean.LoginInfo;
import com.zy.fcs.service.ZtreeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * 查询Controller
 *
 * @author zhanghengchang
 * @date 2018/3/6
 */
@Controller
public class SearchController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(SearchController.class);

    @Autowired
    private ZtreeService ztreeService;

    @GetMapping(value = "/search")
    public String search(@RequestParam String applNo, Model model, HttpSession session) throws Exception{

        // 取得机构号
        LoginInfo loginInfo = (LoginInfo) session.getAttribute("loginInfo");

        if (loginInfo == null) {
            return this.render("login");
        }

        String instNo = loginInfo.getInstNo();

        // 树形结构JSON
        JSONArray treeJson = ztreeService.getTreeJson(instNo, applNo);
        model.addAttribute("treeJson", treeJson);
        model.addAttribute("mediaType", "index");
        model.addAttribute("applNo", applNo);

        return this.render("index");
    }

}
